/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * TelaFuncionarioCadastro.java
 *
 * Created on 08/05/2012, 13:45:26
 */
package salutem.Telas;

import java.awt.Component;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.DefaultTableModel;
import salutem.Beans.CargoBean;
import salutem.Beans.EspecialidadeBean;
import salutem.Beans.FuncionarioBean;
import salutem.Beans.UnidadeBean;
import salutem.DAO.CargoDAO;
import salutem.DAO.EspecialidadeDAO;
import salutem.DAO.FuncionarioDAO;
import salutem.DAO.UnidadeDAO;
import salutem.Utils.Msg;
import salutem.Utils.Params;
import salutem.Utils.Utils;

/**
 *
 * @author Renato Doretto
 */
public class TelaFuncionarioCadastro extends javax.swing.JDialog {

    private boolean inserir;
    private Integer idFunc;
    private FuncionarioDAO daoFunc;
    private UnidadeDAO daoUnidade;
    private CargoDAO daoCargo;
    private EspecialidadeDAO daoEspecialidade;
    private TelaFuncionario telaFunc;
    private List<EspecialidadeBean> espSel;
    private List<EspecialidadeBean> esps;
    private List<CargoBean> cargSel;
    private List<CargoBean> cargs;
    private List<UnidadeBean> uniSel;
    private List<UnidadeBean> unis;

    public TelaFuncionarioCadastro(TelaFuncionario parent, boolean modal) {
        super(parent, modal);
        initComponents();

        this.daoFunc = new FuncionarioDAO();
        this.daoUnidade = new UnidadeDAO();
        this.daoCargo = new CargoDAO();
        this.daoEspecialidade = new EspecialidadeDAO();
        this.telaFunc = parent;
        this.espSel = new ArrayList<EspecialidadeBean>();
        this.esps = new ArrayList<EspecialidadeBean>();
        this.cargSel = new ArrayList<CargoBean>();
        this.cargs = new ArrayList<CargoBean>();
        this.uniSel = new ArrayList<UnidadeBean>();
        this.unis = new ArrayList<UnidadeBean>();
        this.carregarCombos();
    }

    public TelaFuncionarioCadastro(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel3 = new javax.swing.JPanel();
        btSalvar = new javax.swing.JButton();
        btCancelar = new javax.swing.JButton();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        lbNome = new javax.swing.JLabel();
        txNome = new javax.swing.JTextField();
        lbCpf = new javax.swing.JLabel();
        txCpf = new javax.swing.JFormattedTextField();
        lbRg = new javax.swing.JLabel();
        txRg = new javax.swing.JTextField();
        lbSexo = new javax.swing.JLabel();
        cbSexo = new javax.swing.JComboBox();
        lbTelefone = new javax.swing.JLabel();
        txTelefone = new javax.swing.JFormattedTextField();
        lbCelular = new javax.swing.JLabel();
        txCelular = new javax.swing.JFormattedTextField();
        lbRua = new javax.swing.JLabel();
        txRua = new javax.swing.JTextField();
        txNumero = new javax.swing.JTextField();
        lbNumero = new javax.swing.JLabel();
        lbComplemento = new javax.swing.JLabel();
        txComplemento = new javax.swing.JTextField();
        txBairro = new javax.swing.JTextField();
        lbBairro = new javax.swing.JLabel();
        cbEstado = new javax.swing.JComboBox();
        lbEstado = new javax.swing.JLabel();
        cbCidade = new javax.swing.JComboBox();
        lbCidade = new javax.swing.JLabel();
        lbDtAdmissao = new javax.swing.JLabel();
        txDtAdmissao = new org.jdesktop.swingx.JXDatePicker();
        lbDecreto = new javax.swing.JLabel();
        txDecreto = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        cbUnidade = new javax.swing.JComboBox();
        jScrollPane5 = new javax.swing.JScrollPane();
        tbUnidade = new javax.swing.JTable();
        btMaisUni = new javax.swing.JButton();
        btMenosUni = new javax.swing.JButton();
        lbNascimento = new javax.swing.JLabel();
        txDtNascimento = new org.jdesktop.swingx.JXDatePicker();
        lbTpReg = new javax.swing.JLabel();
        cbReg = new javax.swing.JComboBox();
        lbReg = new javax.swing.JLabel();
        txReg = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        lbCargo = new javax.swing.JLabel();
        lbEsp = new javax.swing.JLabel();
        cbCargo = new javax.swing.JComboBox();
        btMaisCargo = new javax.swing.JButton();
        btMenosCargo = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbCargo = new javax.swing.JTable();
        cbEsp = new javax.swing.JComboBox();
        btMaisEsp = new javax.swing.JButton();
        btMenosEsp = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        tbEsp = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        btSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/salutem/imagens/icone-salvar.png"))); // NOI18N
        btSalvar.setText("Salvar");
        btSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSalvarActionPerformed(evt);
            }
        });

        btCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/salutem/imagens/icone-cancelar.png"))); // NOI18N
        btCancelar.setText("Cancelar");
        btCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(182, 182, 182)
                .addComponent(btSalvar, javax.swing.GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btCancelar)
                .addGap(158, 158, 158))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btSalvar)
                    .addComponent(btCancelar))
                .addContainerGap())
        );

        lbNome.setText("Nome");

        txNome.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txNomeKeyTyped(evt);
            }
        });

        lbCpf.setText("CPF");

        try {
            txCpf.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###.###.###-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        txCpf.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txCpfKeyTyped(evt);
            }
        });

        lbRg.setText("RG");

        txRg.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txRgKeyTyped(evt);
            }
        });

        lbSexo.setText("Sexo");

        cbSexo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "<.SELECIONE.>", "MASCULINO", "FEMININO" }));

        lbTelefone.setText("Telefone");

        try {
            txTelefone.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        txTelefone.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txTelefoneKeyTyped(evt);
            }
        });

        lbCelular.setText("Celular");

        try {
            txCelular.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        txCelular.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txCelularKeyTyped(evt);
            }
        });

        lbRua.setText("Rua");

        txRua.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txRuaKeyTyped(evt);
            }
        });

        txNumero.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txNumeroKeyTyped(evt);
            }
        });

        lbNumero.setText("Número");

        lbComplemento.setText("Complemento");

        txBairro.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txBairroKeyTyped(evt);
            }
        });

        lbBairro.setText("Bairro");

        cbEstado.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "<.UF.>", "PR" }));

        lbEstado.setText("Estado");

        cbCidade.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "<.SELECIONE.>", "QUATIGUÁ" }));
        cbCidade.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbCidadeActionPerformed(evt);
            }
        });

        lbCidade.setText("Cidade");

        lbDtAdmissao.setText("Data de admissão");

        txDtAdmissao.setFormats("dd/MM/yyyy");

        lbDecreto.setText("Número decreto");

        txDecreto.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txDecretoKeyTyped(evt);
            }
        });

        jLabel3.setText("Unidades");

        cbUnidade.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jScrollPane5.setPreferredSize(new java.awt.Dimension(452, 100));

        tbUnidade.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "ID", "Nome"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane5.setViewportView(tbUnidade);

        btMaisUni.setText("+");
        btMaisUni.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btMaisUniActionPerformed(evt);
            }
        });

        btMenosUni.setText("-");
        btMenosUni.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btMenosUniActionPerformed(evt);
            }
        });

        lbNascimento.setText("Data de nascimento");

        txDtNascimento.setFormats("dd/MM/yyyy");
        txDtNascimento.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                txDtNascimentoMouseClicked(evt);
            }
        });

        lbTpReg.setText("Tipo do Registro");

        cbReg.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "<..>", "CRF", "CRM" }));

        lbReg.setText("Registro");

        txReg.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txRegKeyTyped(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 503, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lbNome)
                                    .addComponent(txNome, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(cbSexo, javax.swing.GroupLayout.PREFERRED_SIZE, 121, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(lbSexo))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(txTelefone, javax.swing.GroupLayout.DEFAULT_SIZE, 117, Short.MAX_VALUE)
                                            .addComponent(lbTelefone))))
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGap(9, 9, 9)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(jPanel1Layout.createSequentialGroup()
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
                                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                                        .addComponent(lbCpf)
                                                        .addGap(110, 110, 110))
                                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                                        .addComponent(txCpf, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(lbRg)
                                                    .addComponent(txRg, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addGap(10, 10, 10))
                                            .addGroup(jPanel1Layout.createSequentialGroup()
                                                .addComponent(lbCelular)
                                                .addGap(77, 77, 77)
                                                .addComponent(lbNascimento))))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGap(6, 6, 6)
                                        .addComponent(txCelular, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18)
                                        .addComponent(txDtNascimento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lbRua)
                                    .addComponent(txRua, javax.swing.GroupLayout.DEFAULT_SIZE, 412, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lbNumero)
                                    .addComponent(txNumero, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(10, 10, 10))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txComplemento, javax.swing.GroupLayout.DEFAULT_SIZE, 124, Short.MAX_VALUE)
                                    .addComponent(lbComplemento))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lbBairro)
                                    .addComponent(txBairro, javax.swing.GroupLayout.DEFAULT_SIZE, 139, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(cbEstado, 0, 64, Short.MAX_VALUE)
                                    .addComponent(lbEstado))
                                .addGap(6, 6, 6)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lbCidade)
                                    .addComponent(cbCidade, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(10, 10, 10))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(cbReg, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(lbTpReg, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(lbReg)
                                    .addComponent(txReg, javax.swing.GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txDtAdmissao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(lbDtAdmissao))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txDecreto, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                        .addComponent(lbDecreto)
                                        .addGap(116, 116, 116)))))
                        .addGap(0, 0, 0))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addGap(18, 18, 18)
                        .addComponent(cbUnidade, 0, 254, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btMaisUni)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btMenosUni)
                        .addGap(107, 107, 107))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbNome)
                    .addComponent(lbRg)
                    .addComponent(lbCpf))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txRg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txCpf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbSexo)
                    .addComponent(lbTelefone)
                    .addComponent(lbCelular)
                    .addComponent(lbNascimento))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbSexo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txCelular, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txDtNascimento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbRua)
                    .addComponent(lbNumero))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txRua, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txNumero))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbComplemento)
                    .addComponent(lbBairro)
                    .addComponent(lbEstado)
                    .addComponent(lbCidade))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txComplemento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbCidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txBairro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbDecreto)
                    .addComponent(lbDtAdmissao)
                    .addComponent(lbTpReg)
                    .addComponent(lbReg))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(txDecreto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(txDtAdmissao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(cbReg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(txReg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbUnidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(btMaisUni)
                    .addComponent(btMenosUni))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Dados Pessoais", jPanel1);

        lbCargo.setText("Cargo");

        lbEsp.setText("Especialidade");

        cbCargo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        btMaisCargo.setText("+");
        btMaisCargo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btMaisCargoActionPerformed(evt);
            }
        });

        btMenosCargo.setText("-");
        btMenosCargo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btMenosCargoActionPerformed(evt);
            }
        });

        tbCargo.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "ID", "Cargo"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(tbCargo);

        cbEsp.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        btMaisEsp.setText("+");
        btMaisEsp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btMaisEspActionPerformed(evt);
            }
        });

        btMenosEsp.setText("-");
        btMenosEsp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btMenosEspActionPerformed(evt);
            }
        });

        jScrollPane2.setPreferredSize(new java.awt.Dimension(452, 100));

        tbEsp.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "ID", "Especialidade"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane2.setViewportView(tbEsp);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 503, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 503, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                        .addComponent(lbCargo)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cbCargo, javax.swing.GroupLayout.PREFERRED_SIZE, 306, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btMaisCargo)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btMenosCargo))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                        .addComponent(lbEsp)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cbEsp, javax.swing.GroupLayout.PREFERRED_SIZE, 274, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btMaisEsp)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btMenosEsp)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbCargo)
                    .addComponent(cbCargo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btMenosCargo)
                    .addComponent(btMaisCargo))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbEsp)
                    .addComponent(cbEsp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btMaisEsp)
                    .addComponent(btMenosEsp))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 145, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane1.addTab("Outros dados", jPanel2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 528, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 409, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cbCidadeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbCidadeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cbCidadeActionPerformed

    private void btCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCancelarActionPerformed
        this.cancelar();
    }//GEN-LAST:event_btCancelarActionPerformed

    private void btMaisUniActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btMaisUniActionPerformed
        this.addUnidade();
    }//GEN-LAST:event_btMaisUniActionPerformed

    private void btMenosUniActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btMenosUniActionPerformed
        this.removeUnidade();
    }//GEN-LAST:event_btMenosUniActionPerformed

    private void btMaisCargoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btMaisCargoActionPerformed
        this.addCargo();
    }//GEN-LAST:event_btMaisCargoActionPerformed

    private void btMenosCargoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btMenosCargoActionPerformed
        this.removeCargo();
    }//GEN-LAST:event_btMenosCargoActionPerformed

    private void btMaisEspActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btMaisEspActionPerformed
        this.addEspecialidade();
    }//GEN-LAST:event_btMaisEspActionPerformed

    private void btMenosEspActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btMenosEspActionPerformed
        this.removeEspecialidade();
    }//GEN-LAST:event_btMenosEspActionPerformed

    private void btSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSalvarActionPerformed
        this.salvar();
    }//GEN-LAST:event_btSalvarActionPerformed

    private void txNomeKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txNomeKeyTyped
        this.destacarCampo(this.txNome, false);
    }//GEN-LAST:event_txNomeKeyTyped

    private void txCpfKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txCpfKeyTyped
        this.destacarCampo(this.txCpf, false);
    }//GEN-LAST:event_txCpfKeyTyped

    private void txRgKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txRgKeyTyped
        this.destacarCampo(this.txRg, false);
    }//GEN-LAST:event_txRgKeyTyped

    private void txTelefoneKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txTelefoneKeyTyped
        this.destacarCampo(this.txTelefone, false);
    }//GEN-LAST:event_txTelefoneKeyTyped

    private void txCelularKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txCelularKeyTyped
        this.destacarCampo(this.txCelular, false);
    }//GEN-LAST:event_txCelularKeyTyped

    private void txDtNascimentoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_txDtNascimentoMouseClicked
        this.destacarCampo(this.txDtNascimento, false);
    }//GEN-LAST:event_txDtNascimentoMouseClicked

    private void txRuaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txRuaKeyTyped
        this.destacarCampo(this.txRua, false);
    }//GEN-LAST:event_txRuaKeyTyped

    private void txNumeroKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txNumeroKeyTyped
        this.destacarCampo(this.txNumero, false);
    }//GEN-LAST:event_txNumeroKeyTyped

    private void txBairroKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txBairroKeyTyped
        this.destacarCampo(this.txBairro, false);
    }//GEN-LAST:event_txBairroKeyTyped

    private void txRegKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txRegKeyTyped
        this.destacarCampo(this.txReg, false);
    }//GEN-LAST:event_txRegKeyTyped

    private void txDecretoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txDecretoKeyTyped
        this.destacarCampo(this.txDecreto, false);
    }//GEN-LAST:event_txDecretoKeyTyped

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                TelaFuncionarioCadastro dialog = new TelaFuncionarioCadastro(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btCancelar;
    private javax.swing.JButton btMaisCargo;
    private javax.swing.JButton btMaisEsp;
    private javax.swing.JButton btMaisUni;
    private javax.swing.JButton btMenosCargo;
    private javax.swing.JButton btMenosEsp;
    private javax.swing.JButton btMenosUni;
    private javax.swing.JButton btSalvar;
    private javax.swing.JComboBox cbCargo;
    private javax.swing.JComboBox cbCidade;
    private javax.swing.JComboBox cbEsp;
    private javax.swing.JComboBox cbEstado;
    private javax.swing.JComboBox cbReg;
    private javax.swing.JComboBox cbSexo;
    private javax.swing.JComboBox cbUnidade;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JLabel lbBairro;
    private javax.swing.JLabel lbCargo;
    private javax.swing.JLabel lbCelular;
    private javax.swing.JLabel lbCidade;
    private javax.swing.JLabel lbComplemento;
    private javax.swing.JLabel lbCpf;
    private javax.swing.JLabel lbDecreto;
    private javax.swing.JLabel lbDtAdmissao;
    private javax.swing.JLabel lbEsp;
    private javax.swing.JLabel lbEstado;
    private javax.swing.JLabel lbNascimento;
    private javax.swing.JLabel lbNome;
    private javax.swing.JLabel lbNumero;
    private javax.swing.JLabel lbReg;
    private javax.swing.JLabel lbRg;
    private javax.swing.JLabel lbRua;
    private javax.swing.JLabel lbSexo;
    private javax.swing.JLabel lbTelefone;
    private javax.swing.JLabel lbTpReg;
    private javax.swing.JTable tbCargo;
    private javax.swing.JTable tbEsp;
    private javax.swing.JTable tbUnidade;
    private javax.swing.JTextField txBairro;
    private javax.swing.JFormattedTextField txCelular;
    private javax.swing.JTextField txComplemento;
    private javax.swing.JFormattedTextField txCpf;
    private javax.swing.JTextField txDecreto;
    private org.jdesktop.swingx.JXDatePicker txDtAdmissao;
    private org.jdesktop.swingx.JXDatePicker txDtNascimento;
    private javax.swing.JTextField txNome;
    private javax.swing.JTextField txNumero;
    private javax.swing.JTextField txReg;
    private javax.swing.JTextField txRg;
    private javax.swing.JTextField txRua;
    private javax.swing.JFormattedTextField txTelefone;
    // End of variables declaration//GEN-END:variables

    private void cancelar() {
        this.setVisible(false);
        this.dispose();
    }

    protected boolean isInserir() {
        return inserir;
    }

    protected void setInserir(boolean inserir) {
        this.inserir = inserir;
        this.idFunc = null;
    }

    private void destacarCampo(Component c, boolean b) {
        if (b) {
            c.setBackground(Params.COR_CAMPO_VAZIO);
        } else {
            c.setBackground(Params.COR_CAMPO_NORMAL);
        }
    }

    private boolean verificarCampos() {
        boolean aux = false;

        String msg = "Preencha corretamente os campos. \n";

        if (this.txNome.getText().isEmpty()) {
            aux = true;
            this.destacarCampo(this.txNome, aux);
        }
        if (this.txCpf.getText().equals("   .   .   -  ")) {
            aux = true;
            this.destacarCampo(this.txCpf, aux);
        }
        if (this.txRg.getText().isEmpty()) {
            aux = true;
            this.destacarCampo(this.txRg, aux);
        }
        if (this.cbSexo.getSelectedIndex() == 0) {
            aux = true;
            this.destacarCampo(this.cbSexo, aux);
        }
        if (this.txTelefone.getText().equals("(  )    -    ")) {
            aux = true;
            this.destacarCampo(this.txTelefone, aux);
        }
        if (this.txCelular.getText().equals("(  )    -    ")) {
            aux = true;
            this.destacarCampo(this.txCelular, aux);
        }
        if (this.txRua.getText().isEmpty()) {
            aux = true;
            this.destacarCampo(this.txRua, aux);
        }
        if (this.txNumero.getText().isEmpty()) {
            aux = true;
            this.destacarCampo(this.txNumero, aux);
        }
        if (this.txBairro.getText().isEmpty()) {
            aux = true;
            this.destacarCampo(this.txBairro, aux);
        }
        if (this.cbEstado.getSelectedIndex() == 0) {
            aux = true;
            this.destacarCampo(this.cbEstado, aux);
        }
        if (this.cbCidade.getSelectedIndex() == 0) {
            aux = true;
            this.destacarCampo(this.cbCidade, aux);
        }
        if (this.txDecreto.getText().isEmpty()) {
            aux = true;
            this.destacarCampo(this.txDecreto, aux);
        }

        if (aux) {
            Msg.alerta(this, msg);
        }

        return aux;
    }

    protected void preencherCampos(int id) {
        try {
            FuncionarioBean func = daoFunc.getFuncionario(id);
            this.idFunc = func.getIdFuncionario();
            this.txNome.setText(func.getNome().trim().toUpperCase());
            this.txCpf.setText(func.getCpfCnpj().trim());
            this.txRg.setText(func.getRgie().trim());
            this.cbSexo.setSelectedIndex(func.getSexo().equalsIgnoreCase("M") ? 1 : 2);
            if (func.getTelefone() != null) {
                this.txTelefone.setText(func.getTelefone().trim());
            }
            if (func.getCelular() != null) {
                this.txCelular.setText(func.getCelular().trim());
            }

            this.txDtNascimento.getEditor().setText(Utils.convertData(func.getData()));
            this.txRua.setText(func.getRua().trim());
            this.txNumero.setText(String.valueOf(func.getNumero()).trim());
            if (func.getComplemento() != null) {
                this.txComplemento.setText(func.getComplemento().trim().toUpperCase());
            }
            this.txBairro.setText(func.getBairro().trim().toUpperCase());
            this.cbEstado.setSelectedItem(func.getEstado().trim().toUpperCase());
            this.cbCidade.setSelectedItem(func.getCidade().trim().toUpperCase());
            this.txDtAdmissao.getEditor().setText(Utils.convertData(func.getAdmissao()));
            this.txDecreto.setText(String.valueOf(func.getDecreto()).trim());
            if (func.getTipoRegistro() != null && func.getRegistro() != null) {
                this.cbReg.setSelectedItem(func.getTipoRegistro().trim().toUpperCase());
                this.txReg.setText(func.getRegistro().trim().toUpperCase());
            }
            this.uniSel = func.getUnidade();
            this.cargSel = func.getCargo();
            this.espSel = func.getEspecialidade();
            for (int x = 0; x < unis.size(); x++) {
                for (int i = 0; i < uniSel.size(); i++) {
                    if (unis.get(x).getIdUnidade() == uniSel.get(i).getIdUnidade()) {
                        unis.remove(unis.get(x));
                    }
                }
            }
            for (int x = 0; x < esps.size(); x++) {
                for (int i = 0; i < espSel.size(); i++) {
                    if (esps.get(x).getIdEspecialidade() == espSel.get(i).getIdEspecialidade()) {
                        esps.remove(esps.get(x));
                    }
                }
            }
            for (int x = 0; x < cargs.size(); x++) {
                for (int i = 0; i < cargSel.size(); i++) {
                    if (cargs.get(x).getIdCargo() == cargSel.get(i).getIdCargo()) {
                        cargs.remove(cargs.get(x));
                    }
                }
            }
            this.atualizarTbUnidade();
            this.atualizarCbUnidade();
            this.atualizarTbCargo();
            this.atualizarCbCargo();
            this.atualizarTbEspecialidade();
            this.atualizarCbEspecialidade();
        } catch (SQLException e) {
            Msg.erro(this, "Erro ao preencher campos. \n" + e.getMessage());
        }
    }

    private void salvar() {
        if (this.verificarCampos()) {
            return;
        }
        try {
            if (this.isInserir()) {
                FuncionarioBean func = new FuncionarioBean();
                func.setNome(this.txNome.getText().trim().toUpperCase());
                func.setCpfCnpj(this.txCpf.getText().trim().toUpperCase());
                func.setRgie(this.txRg.getText().trim().toUpperCase());
                if (this.cbSexo.getSelectedIndex() == 1) {
                    func.setSexo("M".trim());
                } else {
                    func.setSexo("F".trim());
                }
                func.setTelefone(this.txTelefone.getText().trim().toUpperCase());
                func.setCelular(this.txCelular.getText().trim().toUpperCase());
                func.setData(Utils.convertData(this.txDtNascimento.getEditor().getText()));
                func.setRua(this.txRua.getText().trim().toUpperCase());
                func.setNumero(Integer.parseInt(this.txNumero.getText().trim().toUpperCase()));
                func.setComplemento(this.txComplemento.getText().trim().toUpperCase());
                func.setBairro(this.txBairro.getText().trim().toUpperCase());
                func.setEstado(this.cbEstado.getSelectedItem().toString().trim());
                func.setCidade(this.cbCidade.getSelectedItem().toString().trim());
                func.setAdmissao(Utils.convertData(this.txDtAdmissao.getEditor().getText()));
                func.setDecreto(Integer.parseInt(this.txDecreto.getText().trim().toUpperCase()));
                func.setTipoRegistro(this.cbReg.getSelectedItem().toString().trim());
                func.setRegistro(this.txReg.getText().trim().toUpperCase());
                func.setUnidade(uniSel);
                func.setCargo(cargSel);
                func.setEspecialidade(espSel);
                this.daoFunc.inserir(func);
                Msg.informacao(this, "Salvo com sucesso.");
                this.cancelar();
            } else {
                FuncionarioBean func = new FuncionarioBean();
                func.setIdFuncionario(this.idFunc);
                func.setNome(this.txNome.getText().trim().toUpperCase());
                func.setCpfCnpj(this.txCpf.getText().trim().toUpperCase());
                func.setRgie(this.txRg.getText().trim().toUpperCase());
                if (this.cbSexo.getSelectedIndex() == 1) {
                    func.setSexo("M");
                } else {
                    func.setSexo("F");
                }
                func.setTelefone(this.txTelefone.getText().trim().toUpperCase());
                func.setCelular(this.txCelular.getText().trim().toUpperCase());
                func.setData(Utils.convertData(this.txDtNascimento.getEditor().getText()));
                func.setRua(this.txRua.getText().trim().toUpperCase());
                func.setNumero(Integer.parseInt(this.txNumero.getText().trim().toUpperCase()));
                func.setComplemento(this.txComplemento.getText().trim().toUpperCase());
                func.setBairro(this.txBairro.getText().trim().toUpperCase());
                func.setEstado(this.cbEstado.getSelectedItem().toString().trim());
                func.setCidade(this.cbCidade.getSelectedItem().toString().trim());
                func.setAdmissao(Utils.convertData(this.txDtAdmissao.getEditor().getText()));
                func.setDecreto(Integer.parseInt(this.txDecreto.getText().trim().toUpperCase()));
                func.setTipoRegistro(this.cbReg.getSelectedItem().toString().trim());
                func.setRegistro(this.txReg.getText().trim().toUpperCase());
                func.setUnidade(uniSel);
                func.setCargo(cargSel);
                func.setEspecialidade(espSel);
                this.daoFunc.alterar(func);
                Msg.informacao(this, "Alterado com sucesso.");
                this.cancelar();
            }
        } catch (SQLException e) {
            if (e.getMessage().equals("CPF-DUPLICADO")) {
                Msg.alerta(this, "CPF já cadastrado!!!");
                this.txCpf.requestFocus();
                this.txCpf.selectAll();
            } else {

                Msg.erro(this, "Erro ao salvar. \n" + e.getMessage());
            }
        }

    }

    protected void carregarCbUnidade() {
        this.cbUnidade.removeAllItems();


        this.cbUnidade.addItem("SELECIONE");



        try {
            unis = daoUnidade.getLista();


            for (UnidadeBean unidade : unis) {
                this.cbUnidade.addItem(unidade.getNome().trim().toUpperCase());


            }
        } catch (Exception e) {
            Msg.erro(this, "Erro ao atualizar unidades. \n" + e.getMessage());


        }
    }

    protected void carregarCbEspecialidade() {
        this.cbEsp.removeAllItems();


        this.cbEsp.addItem("SELECIONE");



        try {
            esps = daoEspecialidade.getLista();


            for (EspecialidadeBean esp : esps) {
                this.cbEsp.addItem(esp.getNome().trim().toUpperCase());


            }
        } catch (Exception e) {
            Msg.erro(this, "Erro ao atualizar especialidades. \n" + e.getMessage());


        }
    }

    protected void carregarCbCargo() {
        this.cbCargo.removeAllItems();


        this.cbCargo.addItem("SELECIONE");



        try {
            cargs = daoCargo.getLista();


            for (CargoBean cargo : cargs) {
                this.cbCargo.addItem(cargo.getDescricao().trim().toUpperCase());


            }
        } catch (Exception e) {
            Msg.erro(this, "Erro ao atualizar cargos. \n" + e.getMessage());


        }
    }

    protected void atualizarCbUnidade() {
        this.cbUnidade.removeAllItems();


        this.cbUnidade.addItem("SELECIONE");


        for (UnidadeBean unidade : unis) {
            this.cbUnidade.addItem(unidade.getNome().trim().toUpperCase());


        }
    }

    protected void atualizarCbEspecialidade() {
        this.cbEsp.removeAllItems();


        this.cbEsp.addItem("SELECIONE");


        for (EspecialidadeBean esp : esps) {
            this.cbEsp.addItem(esp.getNome().trim().toUpperCase());


        }
    }

    protected void atualizarCbCargo() {
        this.cbCargo.removeAllItems();


        this.cbCargo.addItem("SELECIONE");


        for (CargoBean cargo : cargs) {
            this.cbCargo.addItem(cargo.getDescricao().trim().toUpperCase());


        }

    }

    private void atualizarTbUnidade() {
        DefaultTableModel modelo = (DefaultTableModel) this.tbUnidade.getModel();
        modelo.setNumRows(0);



        for (int i = 0; i
                < uniSel.size(); i++) {
            modelo.addRow(new Object[]{
                        uniSel.get(i).getIdUnidade(),
                        uniSel.get(i).getNome()});


        }
    }

    private void atualizarTbEspecialidade() {
        DefaultTableModel modelo = (DefaultTableModel) this.tbEsp.getModel();
        modelo.setNumRows(0);



        for (int i = 0; i
                < espSel.size(); i++) {
            modelo.addRow(new Object[]{
                        espSel.get(i).getIdEspecialidade(),
                        espSel.get(i).getNome()});


        }
    }

    private void atualizarTbCargo() {
        DefaultTableModel modelo = (DefaultTableModel) this.tbCargo.getModel();
        modelo.setNumRows(0);



        for (int i = 0; i
                < cargSel.size(); i++) {
            modelo.addRow(new Object[]{
                        cargSel.get(i).getIdCargo(),
                        cargSel.get(i).getDescricao()});


        }
    }

    private void addUnidade() {
        if (this.cbUnidade.getSelectedIndex() != 0) {
            this.uniSel.add(this.unis.get(this.cbUnidade.getSelectedIndex() - 1));


            this.unis.remove(this.cbUnidade.getSelectedIndex() - 1);


        } else {
            Msg.alerta(this, "Selecione uma unidade.");


        }
        this.atualizarCbUnidade();


        this.atualizarTbUnidade();


    }

    private void addEspecialidade() {
        if (this.cbEsp.getSelectedIndex() != 0) {
            this.espSel.add(this.esps.get(this.cbEsp.getSelectedIndex() - 1));


            this.esps.remove(this.cbEsp.getSelectedIndex() - 1);


        } else {
            Msg.alerta(this, "Selecione uma especialidade.");


        }
        this.atualizarCbEspecialidade();


        this.atualizarTbEspecialidade();


    }

    private void addCargo() {
        if (this.cbCargo.getSelectedIndex() != 0) {
            this.cargSel.add(this.cargs.get(this.cbCargo.getSelectedIndex() - 1));


            this.cargs.remove(this.cbCargo.getSelectedIndex() - 1);


        } else {
            Msg.alerta(this, "Selecione um cargo.");


        }
        this.atualizarCbCargo();


        this.atualizarTbCargo();


    }

    private void removeUnidade() {
        int row = this.tbUnidade.getSelectedRow();


        if (row == -1) {
            Msg.alerta(this, "Selecione o registro.");


            return;


        }

        DefaultTableModel modelo = (DefaultTableModel) this.tbUnidade.getModel();


        int id = Integer.parseInt(modelo.getValueAt(row, 0).toString());



        for (int i = 0; i
                < uniSel.size(); i++) {
            if (uniSel.get(i).getIdUnidade() == id) {
                unis.add(uniSel.get(i));
                uniSel.remove(i);


            }
        }
        this.atualizarCbUnidade();


        this.atualizarTbUnidade();


    }

    private void removeEspecialidade() {
        int row = this.tbEsp.getSelectedRow();


        if (row == -1) {
            Msg.alerta(this, "Selecione o registro.");


            return;


        }

        DefaultTableModel modelo = (DefaultTableModel) this.tbEsp.getModel();


        int id = Integer.parseInt(modelo.getValueAt(row, 0).toString());



        for (int i = 0; i
                < espSel.size(); i++) {
            if (espSel.get(i).getIdEspecialidade() == id) {
                esps.add(espSel.get(i));
                espSel.remove(i);


            }
        }
        this.atualizarCbEspecialidade();


        this.atualizarTbEspecialidade();


    }

    private void removeCargo() {
        int row = this.tbCargo.getSelectedRow();


        if (row == -1) {
            Msg.alerta(this, "Selecione o registro.");


            return;


        }

        DefaultTableModel modelo = (DefaultTableModel) this.tbCargo.getModel();


        int id = Integer.parseInt(modelo.getValueAt(row, 0).toString());



        for (int i = 0; i
                < cargSel.size(); i++) {
            if (cargSel.get(i).getIdCargo() == id) {
                cargs.add(cargSel.get(i));
                cargSel.remove(i);


            }
        }
        this.atualizarCbCargo();


        this.atualizarTbCargo();


    }

    private void carregarCombos() {
        this.carregarCbUnidade();


        this.carregarCbEspecialidade();


        this.carregarCbCargo();

    }
}
